package com.nbjtjc.safe.service.edu;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduRequirementSurveyItemsTempletMapper;
import com.nbjtjc.safe.model.edu.EduRequirementSurveyItemsTemplet;

@Service
public class EduRequirementSurveyItemsTempletService {
	@Autowired
  private EduRequirementSurveyItemsTempletMapper eduRequirementSurveyItemsTempletMapper;
	
  @Transactional(rollbackFor = {Throwable.class})
  public Result addList(List<EduRequirementSurveyItemsTemplet> eduRequirementSurveyItemsTemplets){
	        Result result=new Result();
	        if(eduRequirementSurveyItemsTemplets.isEmpty()
	        		){
	            result.setFalse("提交内容不能为空");
	            return result;
	        }
	        int res=eduRequirementSurveyItemsTempletMapper.delete(null);
	        if(res==0){
	            result.setFalse("删除原模板失败");
		        return result;
	        }else{
		        res=eduRequirementSurveyItemsTempletMapper.insertList(eduRequirementSurveyItemsTemplets);
		        if(res==0){
		            result.setFalse("插入失败");
			        return result;
		        }
	        }
	        //以下为单个插入，模板多为批量插入
//	        if(ObjectUtil.isNull(eduRequirementSurveyItemsTemplet.getId())|| ObjectUtil.isNull(eduRequirementSurveyItemsTempletMapper.selectByPrimaryKey(eduRequirementSurveyItemsTemplet.getId()))){
//	        	int res=eduRequirementSurveyItemsTempletMapper.insertSelective(eduRequirementSurveyItemsTemplet);
//	     
//	        if(res==0){
//	            result.setFalse("插入失败");\
//		        return result;

//	        }
//	        }else
//	        {
//	        	int res=eduRequirementSurveyItemsTempletMapper.updateByPrimaryKeySelective(eduRequirementSurveyItemsTemplet);
//	        	 if(res==0){
//	        		 result.setFalse("更新失败");
//		        return result;

//	        	 }
//	        }
	        result.setData(eduRequirementSurveyItemsTemplets);

	        return result;
	    }
  
  
  public Result delete(Integer id){
      Result result=new Result();
      if(ObjectUtil.isNull(id)){
          result.setFalse("删除对象不能为空");
          return result;
      }
      int res  = eduRequirementSurveyItemsTempletMapper.deleteByPrimaryKey(id);
      if(res==0){
          result.setFalse("删除失败");
	        return result;
      }
      return result;
  }

  public Result find(EduRequirementSurveyItemsTemplet eduRequirementSurveyItemsTemplet) {
      Result result = new Result();
      PageHelper.startPage(eduRequirementSurveyItemsTemplet.getPageCurrent(), eduRequirementSurveyItemsTemplet.getPageSize());

      List<EduRequirementSurveyItemsTemplet> eduRequirementSurveyItemsTemplets = eduRequirementSurveyItemsTempletMapper.select(eduRequirementSurveyItemsTemplet);
      result.setData(new PageInfo<>(eduRequirementSurveyItemsTemplets));

      return result;
  }



}
